bitkeeper revision 1.1159.15.1 (4118eb0dXk4yJUHKqaxLdR-bj_e6Zg)
authorgm281@boulderdash.cl.cam.ac.uk <gm281@boulderdash.cl.cam.ac.uk>
Tue, 10 Aug 2004 15:34:37 +0000 (15:34 +0000)
committergm281@boulderdash.cl.cam.ac.uk <gm281@boulderdash.cl.cam.ac.uk>
Tue, 10 Aug 2004 15:34:37 +0000 (15:34 +0000)
The weight of domains created with xm created can be specified with "weight=x" command line option, or put into the config file. Specific scheduler is responsible for handling this additional information. RRobin and Atropos ignore the argument.

19 files changed:
tools/examples/xmdefaults
tools/examples/xmexample
tools/libxc/xc.h
tools/libxc/xc_domain.c
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/create.py
xen/arch/x86/smpboot.c
xen/common/dom0_ops.c
xen/common/domain.c
xen/common/kernel.c
xen/common/sched_atropos.c
xen/common/sched_bvt.c
xen/common/sched_fair_bvt.c
xen/common/sched_rrobin.c
xen/common/schedule.c
xen/include/hypervisor-ifs/dom0_ops.h
xen/include/xen/sched-if.h
xen/include/xen/sched.h

index 0b7c5b2230543dea5792193cf182466b0614185e..0c1f52b69d8b0dc232ed5194a37017e7ded7082f 100644 (file)
@@ -25,6 +25,10 @@ name = "ExampleDomain"
 
 # Which CPU to start domain on? 
 #cpu = -1   # leave to Xen to pick
+# The weight (CPU share) of the domain. Works with all
+# schedulers that have notion of weight (eg BVT). 
+# Default is 1. Float values can be used.
+#weight = 1.5
 
 #----------------------------------------------------------------------------
 # Define network interfaces.
index d6df731c451d026e929977ad19e7dd57eb57415c..b8717fb29a06effd32e3fa40536756af2ea24569 100644 (file)
@@ -55,6 +55,10 @@ name = "VM%d" % vmid
 # Which CPU to start domain on? 
 #cpu = -1   # leave to Xen to pick
 cpu = vmid  # set based on vmid (mod number of CPUs)
+# The weight (CPU share) of the domain. Works with all
+# schedulers that have notion of weight (eg BVT). 
+# Default is 1. Float values can be used.
+#weight = 1.5
 
 #----------------------------------------------------------------------------
 # Define network interfaces.
index b2cf0c67ba4826a38d11843f777b1f164c16000e..d44c1942f50cb8889ad599f37a7f4fb0e798a832 100644 (file)
@@ -48,6 +48,7 @@ int xc_domain_create(int xc_handle,
                      unsigned int mem_kb, 
                      const char *name,
                      int cpu,
+                     float weight,
                      u32 *pdomid);
 int xc_domain_pause(int xc_handle, 
                     u32 domid);
index 10017c74fe7cb6a415e0dcab62d6050510b1a1cf..41bff1fe5f3dad6f81fe0c077a11fd3cb39ba5b4 100644 (file)
@@ -12,6 +12,7 @@ int xc_domain_create(int xc_handle,
                      unsigned int mem_kb, 
                      const char *name,
                      int cpu,
+                     float weight,
                      u32 *pdomid)
 {
     int err;
@@ -20,6 +21,8 @@ int xc_domain_create(int xc_handle,
     op.cmd = DOM0_CREATEDOMAIN;
     op.u.createdomain.domain = (domid_t)*pdomid;
     op.u.createdomain.memory_kb = mem_kb;
+    /* The weight of a domain added to the domain creation code */
+    op.u.createdomain.weight = weight;
     strncpy(op.u.createdomain.name, name, MAX_DOMAIN_NAME);
     op.u.createdomain.name[MAX_DOMAIN_NAME-1] = '\0';
     op.u.createdomain.cpu = cpu;
index 4b5a426b55ff480f44cc19a81b408758fa6c0b3c..d2a12026efe253900f9e486c4da170f39ad37852 100644 (file)
@@ -44,16 +44,19 @@ static PyObject *pyxc_domain_create(PyObject *self,
     unsigned int mem_kb = 0;
     char        *name   = "(anon)";
     int          cpu = -1;
+    float        weight;
     u32          dom = 0;
     int          ret;
 
-    static char *kwd_list[] = { "dom", "mem_kb", "name", "cpu", NULL };
+    static char *kwd_list[] = { "dom", "mem_kb", "name", "cpu", "weight",
+                                                                        NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iisi", kwd_list, 
-                                      &dom, &mem_kb, &name, &cpu) )
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iisif", kwd_list, 
+                                      &dom, &mem_kb, &name, &cpu, &weight) )
         return NULL;
-
-    if ( (ret = xc_domain_create(xc->xc_handle, mem_kb, name, cpu, &dom)) < 0 )
+        
+    if ( (ret = xc_domain_create(xc->xc_handle, mem_kb, name, cpu, 
+                                                     weight, &dom)) < 0 )
         return PyErr_SetFromErrno(xc_error);
 
     return PyInt_FromLong(dom);
index dee5c1cdb220471d70ed39b6ddb93fafaa09ea40..d073909fafba6f126b612835c77c9b55e0fa0423 100644 (file)
@@ -477,6 +477,7 @@ class XendDomainInfo:
         self.config = config
         try:
             self.name = sxp.child_value(config, 'name')
+            self.weight = float(sxp.child_value(config, 'weight'))
             self.check_name(self.name)
             self.memory = int(sxp.child_value(config, 'memory'))
             if self.memory is None:
@@ -687,9 +688,10 @@ class XendDomainInfo:
         if self.recreate: return
         memory = self.memory
         name = self.name
+        weight = self.weight
         cpu = int(sxp.child_value(self.config, 'cpu', '-1'))
         dom = self.dom or 0
-        dom = xc.domain_create(dom= dom, mem_kb= memory * 1024, name= name, cpu= cpu)
+        dom = xc.domain_create(dom= dom, mem_kb= memory * 1024, name= name, cpu= cpu, weight= weight)
         if dom <= 0:
             raise VmError('Creating domain failed: name=%s memory=%d'
                           % (name, memory))
@@ -1125,6 +1127,7 @@ add_device_handler('pci',  vm_dev_pci)
 add_config_handler('name',    vm_field_ignore)
 add_config_handler('memory',  vm_field_ignore)
 add_config_handler('cpu',     vm_field_ignore)
+add_config_handler('weight',  vm_field_ignore)
 add_config_handler('console', vm_field_ignore)
 add_config_handler('image',   vm_field_ignore)
 add_config_handler('device',  vm_field_ignore)
index 286e1d34787c5abda6c057225c301231f74aa02b..f28f20384984967faa9126a3f5f08b94c157b011 100644 (file)
@@ -97,6 +97,10 @@ gopts.var('memory', val='MEMORY',
           fn=set_value, default=128,
           use="Domain memory in MB.")
 
+gopts.var('weight', val='WEIGHT',
+          fn=set_value, default=1,
+          use="Domain cpu weight (default=1).")
+
 gopts.var('console', val='PORT',
           fn=set_int, default=None,
           use="Console port to use. Default is 9600 + domain id.")
@@ -295,7 +299,8 @@ def make_config(vals):
     
     config = ['vm',
               ['name', vals.name ],
-              ['memory', vals.memory ] ]
+              ['memory', vals.memory ],
+              ['weight', vals.weight] ]
     if vals.cpu:
         config.append(['cpu', vals.cpu])
     if vals.blkif:
index bd9c0951ec760b50f9da1a3f275d3fdf4df93bbc..da4130f34e3a8b3d607f9a674473c324fc57289d 100644 (file)
@@ -650,7 +650,7 @@ static void __init do_boot_cpu (int apicid)
 
     cpu = ++cpucount;
 
-    if ( (idle = do_createdomain(IDLE_DOMAIN_ID, cpu)) == NULL )
+    if ( (idle = do_createdomain(IDLE_DOMAIN_ID, cpu, 0)) == NULL )
         panic("failed 'createdomain' for CPU %d", cpu);
 
     set_bit(DF_IDLETASK, &idle->flags);
index 0a4086ef6e06de8206bbfde9a8d70208076a290e..e31d0a6025c930d62bf4fd20b65f048440b1f76d 100644 (file)
@@ -182,9 +182,9 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
             pro = op->u.createdomain.cpu % smp_num_cpus;
 
         ret = -ENOMEM;
-        if ( (d = do_createdomain(dom, pro)) == NULL )
+        if ( (d = do_createdomain(dom, pro, op->u.createdomain.weight))==NULL)
             break;
-
+        
         if ( op->u.createdomain.name[0] )
         {
             strncpy(d->name, op->u.createdomain.name, MAX_DOMAIN_NAME);
index cac4c2edf07d15d34bf830a9d63b75525a1d613b..3f3f876111e7e13ee65c8635d5360962101bc2e2 100644 (file)
@@ -22,7 +22,7 @@ rwlock_t tasklist_lock __cacheline_aligned = RW_LOCK_UNLOCKED;
 struct domain *task_hash[TASK_HASH_SIZE];
 struct domain *task_list;
 
-struct domain *do_createdomain(domid_t dom_id, unsigned int cpu)
+struct domain *do_createdomain(domid_t dom_id, unsigned int cpu, float weight)
 {
     char buf[100];
     struct domain *d, **pd;
@@ -69,7 +69,7 @@ struct domain *do_createdomain(domid_t dom_id, unsigned int cpu)
         spin_lock_init(&d->pcidev_lock);
         INIT_LIST_HEAD(&d->pcidev_list);
 
-        sched_add_domain(d);
+        sched_add_domain(d, weight);
 
         write_lock_irqsave(&tasklist_lock, flags);
         pd = &task_list; /* NB. task_list is maintained in order of dom_id. */
@@ -85,7 +85,7 @@ struct domain *do_createdomain(domid_t dom_id, unsigned int cpu)
     else
     {
         sprintf(d->name, "Idle-%d", cpu);
-        sched_add_domain(d);
+        sched_add_domain(d, weight);
     }
 
     return d;
index 6a39946d700d276f7a6a574c942bd483f0a23b6e..0e0b240b79c91afbb5e6ad1c21560fb97ebab010 100644 (file)
@@ -306,7 +306,7 @@ void cmain(multiboot_info_t *mbi)
     task_hash[TASK_HASH(IDLE_DOMAIN_ID)] = &idle0_task;
 
     /* Create initial domain 0. */
-    new_dom = do_createdomain(0, 0);
+    new_dom = do_createdomain(0, 0, 1);
     if ( new_dom == NULL )
         panic("Error creating domain 0\n");
 
index 53e4519b9fa2728a417667eb3ddeb0b4c1acb56d..b93ea89dd9e8d07a591f76a8f55fe83dcde98311 100644 (file)
@@ -167,8 +167,10 @@ static void requeue(struct domain *sdom)
      * - they shouldn't be on any queue */
 }
 
-/* prepare a task to be added to scheduling */
-static void at_add_task(struct domain *p)
+/* prepare a task to be added to scheduling 
+    TODO - can weight argument can be used to set up the 
+    scheduling parameters? */
+static void at_add_task(struct domain *p, float weight)
 {
     s_time_t now = NOW();
 
index e4ee214b543ab40030ca4c7581e804dac8fc51b8..25e71f0e4d4bdd091e5554b0241ba6ef0ae63cde 100644 (file)
@@ -180,13 +180,16 @@ int bvt_alloc_task(struct domain *p)
 /*
  * Add and remove a domain
  */
-void bvt_add_task(struct domain *p) 
+void bvt_add_task(struct domain *p, float weight
 {
     struct bvt_dom_info *inf = BVT_INFO(p);
     ASSERT(inf != NULL);
     ASSERT(p   != NULL);
 
-    inf->mcu_advance = MCU_ADVANCE;
+    if(weight > 0)
+        inf->mcu_advance = MCU_ADVANCE / weight;
+    else
+        inf->mcu_advance = MCU_ADVANCE;
     inf->domain = p;
     inf->warpback    = 0;
     /* Set some default values here. */
@@ -224,7 +227,7 @@ int bvt_init_idle_task(struct domain *p)
 
     if(bvt_alloc_task(p) < 0) return -1;
 
-    bvt_add_task(p);
+    bvt_add_task(p, 0);
 
     spin_lock_irqsave(&CPU_INFO(p->processor)->run_lock, flags);
     
index 165c128753e09314e27a4e43243bc4be7aa778e3..3e027f8706e4469943c0d8839fb4b8cbc354dfe7 100644 (file)
@@ -152,14 +152,17 @@ int fbvt_alloc_task(struct domain *p)
 /*
  * Add and remove a domain
  */
-void fbvt_add_task(struct domain *p) 
+void fbvt_add_task(struct domain *p, float weight
 {
     struct fbvt_dom_info *inf = FBVT_INFO(p);
 
     ASSERT(inf != NULL);
     ASSERT(p   != NULL);
 
-    inf->mcu_advance = MCU_ADVANCE;
+    if(weight > 0)
+        inf->mcu_advance = MCU_ADVANCE / weight;
+    else
+        inf->mcu_advance = MCU_ADVANCE;
     inf->domain = p;
     if ( p->domain == IDLE_DOMAIN_ID )
     {
@@ -187,7 +190,7 @@ int fbvt_init_idle_task(struct domain *p)
 
     if(fbvt_alloc_task(p) < 0) return -1;
 
-    fbvt_add_task(p);
+    fbvt_add_task(p, 0);
     spin_lock_irqsave(&CPU_INFO(p->processor)->run_lock, flags);
     set_bit(DF_RUNNING, &p->flags);
     if ( !__task_on_runqueue(p) )
index 2ab5604fb51bdc04db25ca3688939d82f2f01e73..28b0f73fa86563579e55962bf1d9adce7ae353c6 100644 (file)
@@ -101,8 +101,9 @@ static int rr_alloc_task(struct domain *d)
    return 0;
 }
 
-/* Setup the rr_dom_info */
-static void rr_add_task(struct domain *p)
+/* Setup the rr_dom_info 
+   The weight argument is ignored as RRobin does not use weights */
+static void rr_add_task(struct domain *p, float weight)
 {
     struct rrobin_dom_info *inf;
     RR_INFO(p)->domain = p;
@@ -121,7 +122,7 @@ static int rr_init_idle_task(struct domain *p)
 {
     unsigned long flags;
     if(rr_alloc_task(p) < 0) return -1;
-    rr_add_task(p);
+    rr_add_task(p, 0);
 
     spin_lock_irqsave(&run_locks[p->processor], flags);
     set_bit(DF_RUNNING, &p->flags);
index d2778e09ed8516670c7b38a0e1c465eb9cf7a623..b37635324b9c22591d92756f3179c46cef1b43d7 100644 (file)
@@ -123,7 +123,7 @@ struct domain *alloc_domain_struct(void)
 /*
  * Add and remove a domain
  */
-void sched_add_domain(struct domain *d) 
+void sched_add_domain(struct domain *d, float weight
 {
     /* Must be unpaused by control software to start execution. */
     set_bit(DF_CTRLPAUSE, &d->flags);
@@ -141,7 +141,7 @@ void sched_add_domain(struct domain *d)
         schedule_data[d->processor].idle = d;
     }
 
-    SCHED_OP(add_task, d);
+    SCHED_OP(add_task, d, weight);
 
     TRACE_2D(TRC_SCHED_DOM_ADD, d->domain, d);
 }
index 8cea03fac2897d6cbfcfc1c1a9661cb3737d92a9..cef857f5e5b7a589c0153710a5bd4be6d6bf17c6 100644 (file)
@@ -55,7 +55,7 @@ typedef struct {
     MEMORY_PADDING;
     u8           name[MAX_DOMAIN_NAME]; /*  8 */
     u32          cpu;                 /* 24 */
-    u32          __pad0;              /* 28 */
+    float        weight;              /* 28 */
     /* IN/OUT parameters. */
     /* If 0, domain is allocated. If non-zero use it unless in use. */
     domid_t      domain;              /* 32 */
index 15f992614ae80c1f18c8bc05e3e9da5c725f458e..9088e61733552c03de13c18c8e08710cfa2d091b 100644 (file)
@@ -38,7 +38,7 @@ struct scheduler
     int          (*init_scheduler) ();
     int          (*init_idle_task) (struct domain *);
     int          (*alloc_task)     (struct domain *);
-    void         (*add_task)       (struct domain *);
+    void         (*add_task)       (struct domain *, float weight);
     void         (*free_task)      (struct domain *);
     void         (*rem_task)       (struct domain *);
     void         (*sleep)          (struct domain *);
index 06b6faf6cc41fc5b3e560f05f3f50641b5afb550..3b8ad6c58b709ed1230bb681e7c3405bb4c07b7e 100644 (file)
@@ -171,7 +171,7 @@ static inline int get_domain(struct domain *d)
 }
   
 extern struct domain *do_createdomain(
-    domid_t dom_id, unsigned int cpu);
+    domid_t dom_id, unsigned int cpu, float weight);
 extern int construct_dom0(struct domain *d, 
                           unsigned long alloc_start,
                           unsigned long alloc_end,
@@ -198,7 +198,7 @@ extern unsigned long wait_init_idle;
 #define set_current_state(_s) do { current->state = (_s); } while (0)
 void scheduler_init(void);
 void schedulers_start(void);
-void sched_add_domain(struct domain *d);
+void sched_add_domain(struct domain *d, float weight);
 void sched_rem_domain(struct domain *d);
 long sched_ctl(struct sched_ctl_cmd *);
 long sched_adjdom(struct sched_adjdom_cmd *);